package com.Ngbussiness.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Ngbussiness.dao.membersDao;
import com.Ngbussiness.dao.impl.membersDaoImpl;
import com.Ngbussiness.util.DataTools;


public class memberLogon extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		//��ȡ�û�ע��ʱ��������
		String mobel=request.getParameter("mobel");
		String name=request.getParameter("name");
		String password=request.getParameter("password");
		//Ĭ���Ա�Ϊ��
		String sex="c4d0";
		membersDao members = new membersDaoImpl();
		System.out.println(DataTools.HexStringhtoString(sex));
		List list=members.samename(mobel);
		if (list.size() > 0) {
			out.print("user_exist");
		}

//		else {
//			//List list1 = members.samename1(DataTools.HexStringhtoString(name));
////			if (list1.size() > 0) {
////                out.println("username_exist");
////			} 
			else {
				boolean b1 = members.Logon(DataTools.HexStringhtoString(name),
						password, mobel, DataTools.HexStringhtoString(sex));
				if (b1 == true) {
					out.print("success");
				} else {
					out.println("error");
				}
			}
	//	}
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
